package org.zecontech.extraplus.datagen;

import net.minecraft.core.RegistrySetBuilder;
import net.minecraft.core.registries.Registries;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.common.data.DatapackBuiltinEntriesProvider;
import net.neoforged.neoforge.data.event.GatherDataEvent;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
import org.zecontech.extraplus.ExtraPlus;
import org.zecontech.extraplus.datagen.levelgen.ModBiomeModiferProvider;
import org.zecontech.extraplus.datagen.levelgen.ModBiomeProvider;
import org.zecontech.extraplus.datagen.levelgen.ModConfiguredFeatureProvider;
import org.zecontech.extraplus.datagen.levelgen.ModPlacedFeatureProvider;
import org.zecontech.extraplus.datagen.loot.ModLootTableProvider;

import java.util.Set;

/**
 * 模组数据生成器
 */
@EventBusSubscriber(modid = ExtraPlus.MOD_ID)
public class ModDataGenerator {

    /**
     * 数据包建造者
     */
    public static RegistrySetBuilder BUILDER =
            new RegistrySetBuilder()
                    .add(NeoForgeRegistries.Keys.BIOME_MODIFIERS,
                            ModBiomeModiferProvider::addBiomeModifiers)
                    .add(Registries.CONFIGURED_FEATURE, ModConfiguredFeatureProvider::configuredFeatures)
                    .add(Registries.PLACED_FEATURE, ModPlacedFeatureProvider::placedFeature)
                    .add(Registries.BIOME, ModBiomeProvider::addBiomes);

    /**
     * 聚集生成客户端数据
     * @param event 客户端生成数据事件
     */
    @SubscribeEvent
    public static void gatherDataClient(GatherDataEvent.Client event) {
        var gen = event.getGenerator();
        var pack = gen.getPackOutput();
        var lookUp = event.getLookupProvider();
        event.createProvider(ModModelProvider::new);
        event.createProvider(ModLanguageProviderZh::new);
        event.createProvider(ModLanguageProviderEn::new);
        event.createProvider(ModLootTableProvider::new);
        event.addProvider(new DatapackBuiltinEntriesProvider(pack,
                lookUp, BUILDER,
                Set.of(ExtraPlus.MOD_ID)));
        event.createProvider(ModItemTagsProvider::new);
        event.createProvider(ModBlockTagsProvider::new);
        event.createProvider(ModBiomeTagsProvider::new);
        event.createProvider(ModRecipeProvider.Runner::new);
        event.createProvider(ModEquipmentInfoProvider::new);
    }
}
